<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>查看用户</title>
		<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/default/easyui.css" />
		<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/icon.css" />
		<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.min.js"></script>
		<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="js/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript">
			var tool =[{
					text:"编辑",
					iconCls:"icon-edit",
					handler:function(){
						var obj  = $("#ta").datagrid("getSelections");
						if(obj == null || obj.length != 1){
							$.messager.alert('提示','选择数据不合法');
						}else{
							$("#e").window({
								title:"编辑用户",
								width:"40%",
								height:"300",
								modal:true,
								href:"editUser"
							});
						}
						
						
					}
				},{
					text:"删除",
					iconCls:"icon-remove",
					handler:function(){
						var obj  = $("#ta").datagrid("getSelections");
						if(obj == null || obj.length != 1){
							$.messager.alert('提示','选择数据不合法');
						}else{
							$.post("user/delUser",{"userid":obj[0].userid},function(data){
								if(data.state == 200){
									$.messager.alert('提示','删除成功');
									$("#ta").datagrid("reload");
								}else{
									$.messager.alert('提示','删除失败');
								}
							});
						}
						
					}
				}];
				
				
				$(function(){
					//根据ajax查询数据
					$.ajax({
						url:"showUsers",
						dataType:"json",
						type:"get",
						success:function(data){
							var str ='';
							for(i=0;i<data.length;i++){
								str+="<tr><td>"+data[i].userid+"</td><td><input type='hidden' value='"+data[i].userid+"'/>"+data[i].username+"</td><td>"+data[i].userpwd+"</td><td>"+data[i].userage+"</td><td><a onclick='delUser("+data[i].userid+")' href='javascript:void(0);'>删除</a></td></tr>";
							}
							$("#t").html(str);
						}
					});
				}); 
		</script>
	</head>
	<body>
		<table id="ta" class="easyui-datagrid" data-options="pageSize:10,toolbar:tool,pagination:true,url:'user/showUsers',singleSelect:false">
			<thead>   
		        <tr>   
		            <th data-options="field:'ck',checkbox:true"></th>
		            <th data-options="field:'userid',width:60">ID</th>   
		            <th data-options="field:'username',width:60">姓名</th>   
		            <th data-options="field:'userpwd',width:60"">密码</th>
		            <th data-options="field:'roleid',width:60"">职位</th>     
		        </tr>   
		    </thead>   
		</table>
	<div id="d" >
	
	</div>
	<div id="e" >
	
	</div>
	</body>
</html>